#!/usr/bin/env drgn

import sys
import os
import time
from drgn.helpers.linux.pid import find_task
from drgn.helpers.linux.fs import fget
from drgn import Object

def main():

    task = find_task(prog, int(sys.argv[1]))
    print(task.pid)

    file = fget(task, int(sys.argv[2]))

    vhost_vsock = Object(prog, 'struct vhost_vsock', address=file.private_data).address_of_()

    vq_rx = Object(prog, 'struct vhost_virtqueue', address=vhost_vsock.vqs[0].address_of_())
    vq_tx = Object(prog, 'struct vhost_virtqueue', address=vhost_vsock.vqs[1].address_of_())
    
    while True:

        print(f'VQ_RX: last_avail_idx: {vq_rx.last_avail_idx}, avail_idx: {vq_rx.avail_idx}, last_used_idx: {vq_rx.last_used_idx}')
        print(f'VQ_TX: last_avail_idx: {vq_tx.last_avail_idx}, avail_idx: {vq_tx.avail_idx}, last_used_idx: {vq_tx.last_used_idx}')

        time.sleep(1)



if __name__ == '__main__':

    tools = '{}/drgn_tools'.format(os.getcwd())
    print(f'insert {tools} into path')
    sys.path.insert(0, tools)
    main()

